package dao

import (
	"miao/config"
	"miao/models"
)

func GetPowerByRoles(roles []string) []models.PowerBase {
	var powers []models.PowerBase
	config.DB.Table("t_base_power p").Joins("LEFT JOIN t_role_power rp ON rp.power_id = p.id").
		Joins("LEFT JOIN t_base_role r ON rp.role_id = r.id").Where("r.name in (?)", roles).Find(powers)
	return powers
}

func GetIdentity() []models.PowerBase {
	var powers []models.PowerBase
	config.DB.Table("t_base_power p").Joins("LEFT JOIN t_role_power rp ON rp.power_id = p.id").
		Where("del_flag = 0").Find(&powers)
	return powers
}
